define(["jQuery", "kendo" ], function ($, kendo ) {
    return {
    	recoveredObject : new Array(),
		
		show : function(){
			
			var url = App.baseUrl+"CommHub/get_recover_list";
			var newData = {
							"file_id": App.fileId,
							"page_id":App.pageId,
						  };
					
			var req = $.ajax({
				type: 'GET',
				url: url,
				data:newData
			});
			req.done(function(msg){
				msg = JSON.parse(msg);
				$("#recover-select").children().each(function(){
					$(this).remove();
				});
				for(var i=0;i<msg.length;i++)
				{
					msg[i].previous_content = JSON.parse(msg[i].previous_content);
					$("#recover-select").append('<option value="' + msg[i].history_id + '">' +msg[i].previous_content.object_type  + '</option>');	
				}
				console.log(msg);
				$( "#recover-dragable-menu").show();
				
				$( "#recover-dragable-menu").css('position','absolute');
			});
		},
        init: function () {
        	console.log("Menu Recover inited...");
			$( "#recover-dragable-menu").draggable({cancel:"#recover-select"});
			
			$(".recover-tool").click(function(e){
        		if(App.isModeArea == 1){
				
					
					App.recoverMenu.show();
				}else{
					alert(App.localize("%view_mode_warning_dialog"));
				}
        	});
			
			$( ".do-recover").click(function(e){
				$( "#recover-dragable-menu").hide();
					$( "#recover-dragable-menu").css('position','absolute');
				var selected_history_id = $("#recover-select").val();
				if(!selected_history_id)
				{
					return;
				}
				else
				{
					var url = App.baseUrl+"CommHub/recover_object";
					var newData = {
									"history_id": selected_history_id,
									"file_id": App.fileId,
									"page_id":App.pageId,
								  };
							
					var req = $.ajax({
						type: 'GET',
						url: url,
						data:newData
					});
					req.done(function(msg){
						App.recoverSingleObject(msg);
					});
				}
			});
			
			$( ".cancel-recover").click(function(e){
				var r=confirm(App.localize("%cancel_confirmation"));
				if (r==true)
				{  
					$( "#recover-dragable-menu").hide();
					$( "#recover-dragable-menu").css('position','absolute');
				}
			});
		}
	}
});